#pragma once

#include <memory>
#include "footage.h"

class regprofile;

namespace icache {

class cache;
class disc_cache;
class mem_cache;
class coordinator;

///single simple point of control of entire icache component;
///panel can create footages, knowing about all types of caches;
class panel {
public:
	panel();
	~panel();
public:
	int avi_prefetch_frames;
	size_t physical_memory() const { return _physical_memory; }
	size_t min_mem_cache() const { return _min_mem_cache; }
	size_t max_mem_cache() const { return _max_mem_cache; }
	disc_size_type min_disc_cache() const { return 16*1024*1024; }
public: ///the following values can be changed dynamically by other threads
	size_t mem_cache_size() const;
	size_t mem_cache_quota() const;
	disc_size_type disc_cache_size() const;
	disc_size_type disc_cache_quota() const;
	//...
	struct data {
		size_t mem_cache_size; ///< only for reading
		int mem_cache_items; ///< only for reading
		size_t mem_cache_quota;
		disc_size_type disc_cache_size; ///< only for reading
		int disc_cache_items; ///< only for reading
		disc_size_type disc_cache_quota;
		string disc_cache_root_path;
		bool disc_cache_erase_on_exit;
		int avi_prefetch_frames;
	};
	void get_data(data & d) const;
	void set_data(data & d); ///< the function corrects and updates data in structure
	void remember(data const & d); ///< saves default data in registry for future runs
public:
	void purge_mem_cache();
	void purge_disc_cache();
public:
	footage_sptr create_avi_footage(const string & filename);
	footage_sptr create_seq_footage(const string & filename);
	footage_sptr create_still_footage(const string & filename);
	footage_sptr create_footage(const string & filename); ///< selects footage's type depending on filename extension
	footage_sptr create_footage(xml::stream & s, string const & reference_path); ///< loads footage's data from xml stream
	cached_image_sptr get_still_image(const string & filename);
	cache & coordinator();
private:
	std::auto_ptr<regprofile> _profile;
	std::auto_ptr<mem_cache> _mc;
	std::auto_ptr<disc_cache> _dc;
	std::auto_ptr<icache::coordinator> _coordinator;
	size_t _physical_memory;
	size_t _min_mem_cache, _max_mem_cache;
};

} //namespace icache